﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AccountTypeFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.AccountTypeFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System;
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.AccountTypeFilter"/> type.
    /// </summary>
    public static class AccountTypeFilter
    {
        /// <summary>
        /// Filters the specified AccountType collection.
        /// </summary>
        /// <param name="collection">The AccountType collection.</param>
        /// <param name="objectToMatch">The AccountType to match.</param>
        /// <returns>List of filtered AccountTypes</returns>
        public static IQueryable<AccountType> Filter(this IObjectSet<AccountType> collection, AccountType objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from account in collection
                where (objectToMatch.Id == 0 || account.Id == objectToMatch.Id) &&
                    (objectToMatch.Name == null || account.Name.Equals(objectToMatch.Name, StringComparison.InvariantCultureIgnoreCase))
                select account;
        }
    }
}